import { defineStore } from "pinia";
import { get, post } from "@/utils/request";
import {ref} from 'vue'

export const useMentorClassStore = defineStore('mClass', () => {
  // 班级管理表单数据
  let mClassData = ref(null)
  const mClassRequest = async (name,grade,pageNum,pageSize) => {
    try {
      const response = await get('/teacher/students',{
        name:name,
        grade:grade,
        pageNum:pageNum,
        pageSize:pageSize,
      })
        mClassData.value = response.data.list
    } catch (error) {
      console.error(error)
    }
  }

  // 重置密码
  const mCChangePasswordRequest = async (userId,password) => {
    try {
      const response = await get('/teacher/student/resetPassword',{
        userId:userId,
        password:password
      })
        mClassData.value = response.data
    } catch (error) {
      console.error(error)
    }
  }

  // 班级管理学生详情页
  let mCDetailData = ref({})
  const mCDetailRequest = async (userId) => {
    try {
      const response = await post('/teacher/student/info',{
        userId:userId
      })
        mCDetailData.value = response.data
    } catch (error) {
      console.error(error)
    }
  }


  return {mClassData,mClassRequest,
    mCChangePasswordRequest,
    mCDetailData,mCDetailRequest
  }
})